home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / std / c++ / 623 < prev    next >
Encoding:
Internet Message Format  |  1996-08-06  |  2.9 KB

  1. Path: chronicle.mti.sgi.com!austern
  2. From: kanze@gabi-soft.fr (J. Kanze)
  3. Newsgroups: comp.std.c++
  4. Subject: Re: constant-expression extension
  5. Date: 04 Mar 1996 10:33:13 PST
  6. Organization: GABI Software, Sarl.
  7. Approved: austern@isolde.mti.sgi.com
  8. Message-ID: <KANZE.96Mar4120725@gabi.gabi-soft.fr>
  9. References: <4h775a$m4s@ugress.uib.no>
  10. NNTP-Posting-Host: isolde.mti.sgi.com
  11. X-Original-Date: 04 Mar 1996 11:07:25 GMT
  12. In-Reply-To: boukanov@afrodite.fi.uib.no's message of 01 Mar 1996 09:03:14 PST
  13. X-Auth: PGPMoose V1.1 PGP comp.std.c++
  14.     iQBUAwUBMTs3jEy4NqrwXLNJAQHttgH2I8k6LxFbUszg7i++JcLpWaPqGZjAnuqC
  15.     junGLjF+xw184klypRwKX3C71LUIEZqq7iRpJeReUW+2k4XAx0+f
  16.     =qztA
  17. Originator: austern@isolde.mti.sgi.com
  18.  
  19. In article <4h775a$m4s@ugress.uib.no> boukanov@afrodite.fi.uib.no (Igor
  20. Boukanov) writes:
  21.  
  22. |>    My proposal is to change definition of the 
  23. |> "integral constant-expression"[5.19] to something like this:
  24.  
  25. |> An    integral   constant-expression is an expression that can be calculated
  26. |> at the compilation phase. 
  27.  
  28. |> And according to this one would be able to use inline
  29. |> functions in constant-expressions and instead of writing:
  30.  
  31. |> #define ALIGN(number, base) ((number + base - 1) / base * base)
  32. |> #define MAX(x, y) ((x > y) ? (x) : (y))
  33. |> #define GRAD_TO_RADIAN(x) (x * 3.1415926 / 180)
  34.  
  35. |>    char buf[ALIGN(50, sizeof(float))];
  36. |>    char buf2[MAX(sizeof(long), sizeof(double))];
  37. |>    const double angle = GRAD_TO_RADIAN(30);
  38.  
  39. |> one can write:
  40.  
  41. |> inline unsigned T align(unsigned number, unsigned base) {
  42. |>    return ((number + base - 1) / base * base);
  43. |> } 
  44.  
  45. |> template<class T> inline T max(T x, T y){ 
  46. |>    return (x > y) ? x : y;
  47.  
  48. |> inline double grad_to_radian(double x){
  49. |>    return x * 3.1415926 / 180;
  50. |> }
  51.  
  52. |>    char buf[align(50, sizeof(float))];
  53. |>    char buf2[max(sizeof(long), sizeof(double))];
  54. |>    const double angle = grad_to_radian(30);
  55.  
  56. |> So what do you think about this?
  57.  
  58. That it would be nice, but that there are two very big problems:
  59.  
  60. 1. It would basically require a complete C++ interpreter in the
  61. compiler, and
  62.  
  63. 2. It would make the notion of constant expression somewhat
  64. implementation dependant.  Suppose my compiler implements the function
  65. sin as an inline invocation of a compiler built-in.  Can I then use sin
  66. in a constant expression?
  67. -- 
  68. James Kanze           (+33) 88 14 49 00          email: kanze@gabi-soft.fr
  69. GABI Software, Sarl., 8 rue des Francs Bourgeois, 67000 Strasbourg, France
  70. Conseils, itudes et rialisations en logiciel orienti objet --
  71.               -- A la recherche d'une activiti dans une region francophone
  72. ---
  73. [ comp.std.c++ is moderated.  To submit articles: Try just posting with your 
  74.                 newsreader.  If that fails, use mailto:std-c++@ncar.ucar.edu
  75.   comp.std.c++ FAQ: http://reality.sgi.com/austern/std-c++/faq.html
  76.   Moderation policy: http://reality.sgi.com/austern/std-c++/policy.html
  77.   Comments? mailto:std-c++-request@ncar.ucar.edu 
  78. ]
  79.